package com.sskj.b70.v.activity;

import android.graphics.Color;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.bulong.rudeness.RudenessScreenHelper;
import com.scwang.smartrefresh.header.BezierCircleHeader;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.sskj.b70.R;
import com.sskj.b70.common.adapter.BaseAdapter;
import com.sskj.b70.common.adapter.ViewHolder;
import com.sskj.b70.common.decoration.DividerLineItemDecoration;
import com.sskj.b70.common.widget.ToolBarLayout;
import com.sskj.b70.m.bean.NoticeList;
import com.sskj.b70.p.fragment.NoticePresenter;
import com.sskj.b70.utils.ClickUtil;
import com.sskj.b70.v.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * ProjectName：bfex
 * DESC: (类描述)
 * Created by 李岩 on 2018/6/29 0029
 * updateName:(修改人名称)
 * updateTime:(修改时间)
 * updateDesc:(修改内容)
 */
public class InforMationActivity extends BaseActivity<NoticePresenter> {
    @BindView(R.id.notice_toolbar)
    ToolBarLayout mNoticeToolbar;

    @BindView(R.id.notice_recyclerView)
    RecyclerView noticeRecyclerView;
    @BindView(R.id.notice_refresh)
    SmartRefreshLayout refreshLayout;

    private BaseAdapter<NoticeList> adapter;


    @Override
    protected int getLayoutResId() {
        return R.layout.activity_infor_mation;
    }

    @Override
    public NoticePresenter getPresenter() {
        return new NoticePresenter();
    }

    @Override
    protected void initView() {
        super.initView();
        mNoticeToolbar.setLeftButtonOnClickLinster(v -> finish());

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        noticeRecyclerView.setLayoutManager(linearLayoutManager);
//        noticeRecyclerView.addItemDecoration(new DividerItemDecoration(mActivity, DividerItemDecoration.VERTICAL));
        noticeRecyclerView.addItemDecoration(new DividerLineItemDecoration(this)
                .setLastDraw(false)
                .setPaintWidth((int) RudenessScreenHelper.pt2px(this, 2))
                .setDividerColor(Color.parseColor("#f5f5f5")));
        refreshLayout.setOnRefreshListener(refreshLayout1 -> {
            refreshLayout.finishRefresh();
            mPresenter.getData(10);
        });
        refreshLayout.setRefreshHeader(new BezierCircleHeader(this));
        adapter = new BaseAdapter<NoticeList>(R.layout.recycler_item_notice, new ArrayList<>(), noticeRecyclerView) {
            @Override
            public void bind(ViewHolder holder, NoticeList item) {
                holder.setText(R.id.notice_title, item.getTitle());
                holder.setText(R.id.notice_time, item.getCreateTime());
//                holder.setText(R.id.notice_time, item.getCreateTime().get(0) + "  " + item.getCreateTime().get(1));
                ClickUtil.click(holder.getView(R.id.notice_root), () -> WebViewActivity.start(mActivity, item.getId()));
            }
        };
        adapter.setEmtyView();
    }

    @Override
    public void initData() {
        mPresenter.getData(10);
    }

    public void setData(List<NoticeList> data) {
        adapter.setNewData(data);
        noticeRecyclerView.setAdapter(adapter);
    }
}
